# Maintainer: Anatol Pomozov <anatol.pomozov@gmail.com>

pkgname=rubygems
pkgdesc='Package management framework for Ruby'
pkgver=3.2.21
pkgrel=1
arch=(any)
url='https://rubygems.org/'
license=(MIT)
# To avoid circular dependency with ruby, move it to makedepends
makedepends=(ruby)
backup=(etc/gemrc)
checkdepends=(rake)
source=(rubygems-$pkgver.zip::https://github.com/rubygems/rubygems/archive/v${pkgver}.zip
        stop_so_duplication.patch
	gemrc)
sha512sums=('3375514dfd4fda17ed1ea1ac61ea90c94bbce2022c62462e27893e11af18e0bfaeef0566b55cdc2e2f6daa8bf905219f42312acdbade2d78ec2dd4449e171661'
            '9919490bbf7dba979a1df7543e62eb3fca48e8a516e6b6ab0a73080952e1b58599b7f233259d122dc66bf93f032b434d70e0dd448a1cb86513f01acb51b2120e'
            '8cafd14d414ee3c16aa94f79072bc6c100262f925dc1300e785846c3fabbbbffc1356b8e2223af5684e3340c55032d41231179ffa948bb12e01dbae0f4131911')

prepare() {
  cd rubygems-${pkgver}
  patch -p1 < ../stop_so_duplication.patch
}

check() {
  cd rubygems-${pkgver}

  # disable as it requires a lot of ruby-* dependencies
  #rake test
}

package() {
  depends+=(ruby)
  cd rubygems-${pkgver}

  install -D -m644 "${srcdir}"/gemrc "${pkgdir}/etc/gemrc"

  local rubyver=$(ruby --version | sed -r 's|^ruby ([[:digit:]]+\.[[:digit:]]+\.).*$|\1|')0

  install -d "${pkgdir}/usr/lib/ruby/${rubyver}/"
  install -D -m755 bin/gem "${pkgdir}/usr/bin/gem"
  cp -r lib/* "${pkgdir}/usr/lib/ruby/${rubyver}/"
  install -D -m644 MIT.txt "${pkgdir}/usr/share/licenses/rubygems/MIT.txt"
}
